package servlet;


import util.JDBCUtil;
import model.User;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

//
//@WebServlet(urlPatterns = "/SearchUserServlet1.do")
public class SearchUserServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response)  {
            List<Map<String, Object>> userList = new ArrayList<>();
            JDBCUtil jdbcUtil = new JDBCUtil();
            String username=request.getParameter("username");

            try {
                String sql = "SELECT * FROM 02_38_yangyang where username=?"; // 假设数据库表名为 users
                ResultSet resultSet = jdbcUtil.prepareQuery(sql,username);
                User user=new User();
                if (resultSet.next()) {

                   int id=resultSet.getInt("user_id");
                    String gender = resultSet.getString("gender");
                    String profession = resultSet.getString("profession");
                    String favor = resultSet.getString("favor");
                    String description = resultSet.getString("description");
                     int state=resultSet.getInt("state");
                     int role= resultSet.getInt("role");
                }

                request.getRequestDispatcher("/searchUser.jsp").forward(request, response);

            } catch (SQLException ex) {
                throw new RuntimeException(ex);
            } catch (ServletException e) {
                throw new RuntimeException(e);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }

            // 将 userList 存储为请求属性
                request.setAttribute("userList", userList);



        }
}

